import request from "@/utils/request";
import type {
  PlatformAttributeArray,
  skuSalesAttributeArray,
  skuPictureListArray,
  addSkusavedata,
} from "./model/sku";

enum Api {
  gtePlatformAttributeUrl = "/admin/product/attrInfoList",
  getSalesAttributeUrl = "/admin/product/spuSaleAttrList",
  getPictureListUrl = "/admin/product/spuImageList",
  addsaveSkuInfoUrl = "/admin/product/saveSkuInfo",
}

/**
 *
 * @param category1Id   请求一级分类的id
 * @param category2Id   请求二级分类的id
 * @param category3Id   请求三级分类的id
 * @returns  返回值的类型是:
 */
export const gtePlatformAttributeApi = async (
  category1Id: number,
  category2Id: number,
  category3Id: number
) => {
  return await request.get<any, PlatformAttributeArray>(
    Api.gtePlatformAttributeUrl +
      `/${category1Id}/${category2Id}/${category3Id}`
  );
};

/**
 *
 * @param spuId   spu这属性的  id  spuId  当前项的id
 * @returns skuSalesAttributeArray
 */
export const getSalesAttributeApi = (spuId: number) => {
  return request.get<any, skuSalesAttributeArray>(
    Api.getSalesAttributeUrl + `/${spuId}`
  );
};

/**
 *
 * @param spuId   spu这属性的  id  spuId  当前项的id
 * @returns
 */
export const getPictureListApi = (spuId: number) => {
  return request.get<any, skuPictureListArray>(
    Api.getPictureListUrl + `/${spuId}`
  );
};

// spu页面添加Sku属性
export const addsaveSkuInfoApi = (data: addSkusavedata) => {
  console.log(data);
  return request.post(Api.addsaveSkuInfoUrl, data);
};
